package com.yxjwzpx.management.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.yxjwzpx.management.domain.FaultReport;
import com.yxjwzpx.management.service.IFaultReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 故障上报Controller
 * 
 * @author yxjwzpx
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/management/report")
public class FaultReportController extends BaseController
{
    @Autowired
    private IFaultReportService faultReportService;

    /**
     * 查询故障上报列表
     */
    @PreAuthorize("@ss.hasPermi('management:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaultReport faultReport)
    {
        startPage();
        List<FaultReport> list = faultReportService.selectFaultReportList(faultReport);
        return getDataTable(list);
    }

    /**
     * 导出故障上报列表
     */
    @PreAuthorize("@ss.hasPermi('management:report:export')")
    @Log(title = "故障上报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaultReport faultReport)
    {
        List<FaultReport> list = faultReportService.selectFaultReportList(faultReport);
        ExcelUtil<FaultReport> util = new ExcelUtil<FaultReport>(FaultReport.class);
        util.exportExcel(response, list, "故障上报数据");
    }

    /**
     * 获取故障上报详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:report:query')")
    @GetMapping(value = "/{reportId}")
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId)
    {
        return success(faultReportService.selectFaultReportByReportId(reportId));
    }

    /**
     * 新增故障上报
     */
    @PreAuthorize("@ss.hasPermi('management:report:add')")
    @Log(title = "故障上报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaultReport faultReport)
    {
        return toAjax(faultReportService.insertFaultReport(faultReport));
    }

    /**
     * 修改故障上报
     */
    @PreAuthorize("@ss.hasPermi('management:report:edit')")
    @Log(title = "故障上报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaultReport faultReport)
    {
        return toAjax(faultReportService.updateFaultReport(faultReport));
    }

    /**
     * 删除故障上报
     */
    @PreAuthorize("@ss.hasPermi('management:report:remove')")
    @Log(title = "故障上报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportIds}")
    public AjaxResult remove(@PathVariable Long[] reportIds)
    {
        return toAjax(faultReportService.deleteFaultReportByReportIds(reportIds));
    }
}
